home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / hotspots / reqfiles / animate.sx next >
Encoding:
Text File  |  1996-05-21  |  3.7 KB  |  110 lines  |  [TEXT/ttxt]

  1. in module DemoModule
  2.  
  3. --*******************************************************************************
  4. --*        Class name:    Animation
  5. --*                                            
  6. --*     Inherits from: TwoDShape                                    
  7. --*        Class type: Concrete
  8. --*         Component: Animation
  9. --*
  10. --*       Description: This is a subclass of TwoDShape takes a series of bitmaps
  11. --*                    and flips through them at the given scale.
  12. --*
  13. --*             Usage: an := new Animation series:<a series of bitmaps> \
  14. --*                                        scale:8
  15. --*
  16. --*               IVs:    animationClock
  17. --*                    series
  18. --*                    cell
  19. --*
  20. --*           Methods:    start
  21. --*                    stop
  22. --*                    tick
  23. --*                    init
  24. --*                    
  25. --*    Required files:    none
  26. --*                    
  27. --*             Notes: 
  28. --*
  29. --*            Author:    Steve Mayer, Su Quek - Kaleida Labs, Inc.
  30. --*******************************************************************************
  31. class Animation (TwoDShape)
  32. instance variables
  33.     animationClock
  34.     series
  35.     cell
  36. end
  37.  
  38. --*=============================================================================*
  39. --*       Method name:    start
  40. --*             Class:    Animation
  41. --*             Usage: start self
  42. --*-----------------------------------------------------------------------------*
  43. --*       Description: Starts the animation clock. 
  44. --*                    (i.e. starts flipping the bitmaps)
  45. --*=============================================================================*
  46. method start self {class Animation} ->
  47. (
  48.     self.animationClock.rate := 1
  49. )
  50.  
  51. --*=============================================================================*
  52. --*       Method name:    stop
  53. --*             Class:    Animation
  54. --*             Usage: stop self
  55. --*-----------------------------------------------------------------------------*
  56. --*       Description: Stops the animation clock. 
  57. --*                    (i.e. stops flipping the bitmaps)
  58. --*=============================================================================*
  59. method stop self {class Animation} ->
  60. (
  61.     self.animationClock.rate := 0
  62. )
  63.  
  64. --*=============================================================================*
  65. --*       Method name:    tick
  66. --*             Class:    Animation
  67. --*             Usage: tick self
  68. --*-----------------------------------------------------------------------------*
  69. --*       Description: Change current cell to the next cell in the series.
  70. --*                    This method gets called at each tick of the animation clock.
  71. --*=============================================================================*
  72. method tick self {class Animation} clk ->
  73. (
  74.     --*=========================================================================*
  75.     --* Change to the appropriate cell
  76.     --*=========================================================================*
  77.     self.boundary := self.series[self.cell]
  78.     
  79.     --*=========================================================================*
  80.     --* Get the next cell. Wrap around if at the end.
  81.     --*=========================================================================*
  82.     self.cell := ((mod self.cell self.series.size) as Integer) + 1
  83. )
  84.  
  85. --*=============================================================================*
  86. --*       Method name:    init
  87. --*             Class:    Animation
  88. --*             Usage: init self [series:<Array>] \
  89. --*                              [scale:<Number>]
  90. --*-----------------------------------------------------------------------------*
  91. --*       Description: Sets up the callback to flip throught the series of bitmaps
  92. --*=============================================================================*
  93. method init self {class Animation} #rest args \
  94.                                    #key series:(#(new Oval x2:100 y2:100)) \
  95.                                         scale:(5) ->
  96. (
  97.     apply nextMethod self boundary:(series[1]) fill:defaultBrush args
  98.     
  99.     self.series := series
  100.     self.cell := 1
  101.     
  102.     local animationClock := (new Clock scale:scale)
  103.     addPeriodicCallBack animationClock (clk -> tick self clk) animationClock #() 1
  104.     animationClock.rate := 0
  105.     self.animationClock := animationClock
  106.     self
  107. )
  108.  
  109.  
  110.